from selenium.webdriver.common.by import By
from page.base_page_helin import BasePage

class AddSkdPage(BasePage):
    # 进入添加应收款页面定位器
    cw_locator=(By.LINK_TEXT,"财务")
    tjskd_locator=(By.LINK_TEXT,"添加收款单")

    # 添加收款单定位器
    fzr_locator=(By.ID,"owner_name")
    xzfzr_table_locator=(By.XPATH,'//*[@id="d_content"]')
    fzrok_locator=(By.XPATH,"/html/body/div[8]/div[3]/div/button[1]")
    ysk_locator=(By.XPATH,'//*[@id="receivables"]')

    xzysk_table_locator=(By.XPATH,'//*[@id="data"]')
    yskok_locator=(By.XPATH,"/html/body/div[7]/div[3]/div/button[1]")
    skje_locator=(By.ID,"money")
    sksj_locator=(By.XPATH,'//*[@id="pay_time"]')
    zt_locator=(By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[7]/td[2]')
    ms_locator=(By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[8]/td[2]/textarea')
    bcskd_locator=(By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')

    # 进入添加收款单页面
    def click_cw(self):
        self.driver.find_element(*self.cw_locator).click()

    def click_tjskd(self):
        self.driver.find_element(*self.tjskd_locator).click()

    # 添加收款单
    def add_fzr(self,fzr):
        self.driver.find_element(*self.fzr_locator).click()
        tbody=self.driver.find_element(*self.xzfzr_table_locator)
        trs=tbody.find_elements(By.TAG_NAME,"tr")
        for tr in trs:
            tds=tr.find_elements(By.TAG_NAME,"td")
            if tds[1].text==fzr:
                tds[0].click()
                break
        self.driver.find_element(*self.fzrok_locator).click()


    def add_ysk(self,ysk):
        self.driver.find_element(*self.ysk_locator).click()
        tbody=self.driver.find_element(*self.xzysk_table_locator)
        trs=tbody.find_elements(By.TAG_NAME,"tr")
        for tr in trs:
            tds=tr.find_elements(By.TAG_NAME,"td")
            if tds[1].text==ysk:
                tds[0].find_element(By.CSS_SELECTOR,'input[name="receivables"]').click()
                break
        self.driver.find_element(*self.yskok_locator).click()

    def add_skje(self,skje):
        self.driver.find_element(*self.skje_locator).clear()
        self.driver.find_element(*self.skje_locator).send_keys(skje)

    def add_sksj(self,sksj):
        self.driver.find_element(*self.sksj_locator).send_keys(sksj)

    def add_zt(self):
        self.driver.find_elements(*self.zt_locator)[0].click()

    def add_ms(self,ms):
        self.driver.find_element(*self.ms_locator).send_keys(ms)

    def add_bc(self):
        self.driver.find_element(*self.bcskd_locator).click()
